﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ActivityController : ControllerBase
    {
        private readonly BitDbContext _bit;

        public ActivityController(BitDbContext BitDB)
        {
            _bit = BitDB;
        }
        /// <summary>
        /// 查询表
        /// </summary>
        /// <returns></returns>

        //[HttpGet]
        //public Result Get()
        //{

        //    Result result = new Result();
        //    result.Data = _bit.EM_activity.ToList();
        //    return result;
        //}


        /// <summary>
        /// 查找活动ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public Result GetT(Guid id)
        {

            Result result = new Result();
            result.Data = _bit.EM_activity.Where(w => w.ID == id).ToList();
            return result;
        }




        /// <summary>
        /// 修改活动
        /// </summary>
        /// <param name="act"></param>
        /// <returns></returns>
        [HttpPut]
        public Result UP([FromBody] EM_activity act)
        {
            Result result = new Result();
            _bit.EM_activity.Update(act);
            result.Data = _bit.SaveChanges();
            return result;
        }



        /// <summary>
        /// 删除活动
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public Result DelUser(Guid id)
        {
            Result result = new Result();
            EM_activity? user = _bit.EM_activity.Where(w => w.ID == id).SingleOrDefault();
            if (user != null)
                _bit.EM_activity.Remove(user);
            result.Data = _bit.SaveChanges();
            return result;
        }
        /// <summary>
        /// 增加活动
        /// </summary>
        /// <param name="ware"></param>
        /// <returns></returns>
        [HttpPost]
        public Result AddWare([FromBody] EM_activity ware)
        {
            Result result = new Result();
            _bit.EM_activity.Add(ware);
            result.Data = _bit.SaveChanges();
            return result;
        }

    }
}
